package com.magictower.primary.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

import com.magictower.primary.R;
import com.magictower.primary.common.SPConstant;

/**
 * Created by kejunzhan on 2017/12/7.
 */

public class Setup3Activity extends BaseSetupActivity {

    private EditText etPhone;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_setup3);

        etPhone = (EditText) findViewById(R.id.et_phone);

        String phone = mPref.getString(SPConstant.SAFE_PHONE, "");
        if (!TextUtils.isEmpty(phone)) {
            etPhone.setText(phone);
        }

    }

    @Override
    public void showNextPage() {

        if (TextUtils.isEmpty(etPhone.getText())) {
            Toast.makeText(this, "请输入手机号", Toast.LENGTH_SHORT).show();
        } else {
            mPref.edit().putString(SPConstant.SAFE_PHONE, etPhone.getText().toString()).apply();
            startActivity(new Intent(Setup3Activity.this, Setup4Activity.class));
            finish();
            overridePendingTransition(R.anim.page_alpha_in, R.anim.page_tran_out);
        }
    }

    @Override
    public void showPreviousPage() {
        startActivity(new Intent(Setup3Activity.this, Setup2Activity.class));
        finish();
        overridePendingTransition(R.anim.page_tran_in, R.anim.page_alpha_out);
    }

    public void selectContact(View view) {
        startActivityForResult(new Intent(Setup3Activity.this, ContactActivity.class), 0);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {

        if (resultCode == RESULT_OK) {
            String phone = data.getStringExtra("phone").replaceAll("-", "").replaceAll(" ", "");
            etPhone.setText(phone);
        }

        super.onActivityResult(requestCode, resultCode, data);
    }
}
